<template>

 <el-dialog title="出版社 - 回收站"
	           :close-on-click-modal="false"
	           :close-on-press-escape="false"
	           :visible.sync="open" custom-class="form-dialog form-dialog-large" append-to-body>


  <div class="trash-container">
    <!-- 搜索 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">

      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="联系电话" prop="tel">
        <el-input
          v-model="queryParams.tel"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
	
	
	  <!-- 操作 -->
	  <el-row :gutter="10" class="mb8">
		  
		  <el-col :span="1.5">
			  <el-button
				  type="warning"
				  plain
				  icon="el-icon-refresh-left"
				  size="mini"
				  :disabled="multiple"
				  @click="handleRestore"
				  v-hasPermi="['knowledge:publisher:restore']"
			  >恢复</el-button>
		  </el-col>
    
		
		
		  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
	  </el-row>
    
    

    <!-- 列表 -->
    <el-table v-loading="loading" ref="listTable" :data="publisherList" @selection-change="handleSelectionChange" @sort-change="handleSortChange" :height="tableHeight">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="编号" align="center" prop="id" /> -->
      <el-table-column label="名称" align="center" prop="name"  />
      <el-table-column label="地址" align="center" prop="address"  />
      <el-table-column label="联系电话" align="center" prop="tel"  />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">

          <el-button
            class="text-warning"
            size="mini"
            type="text"
            icon="el-icon-refresh-left"
            @click="handleRestore(scope.row)"
            v-hasPermi="['knowledge:publisher:restore']"
          >恢复</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
  </el-dialog>
</template>

<script>
import * as publisherService from "@/api/service/knowledge/PublisherService";
export default {
  name: "PublisherTrash",
	props:{
		show:{
			type: Boolean
		}
	},
  components:{
  },
  data() {
    return {
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出版社表格数据
      publisherList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        address: null,
        tel: null,
      },
      // 表单参数
      form: null,
      // 回收站
      trash: null

    };
  },
  created() {
    this.open = true;
    this.getList();
  },
  watch: {
    open(newVal){
      if(!newVal){
        this.$emit('update:show', null);
      }
    },
  },
  methods: {
    /** 查询出版社列表 */
    getList() {
      this.loading = true;

      // 默认排序设置
      //if(!this.queryParams.orderByColumn){
      //  this.queryParams.orderByColumn = 'createTime';
      //  this.queryParams.isAsc = 'descending';
      //}
      publisherService.findDeletedList(this.queryParams).then(res => {
        this.publisherList = res.items;
        this.total = res.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 恢复按钮操作 */
    handleRestore(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认恢复出版社编号为"' + ids + '"的数据项?').then(function() {
          return publisherService.restore(ids);
        }).then(() => {

        this.$modal.success("恢复成功");
        this.open = false;
        this.$emit('success', {});
        }).catch(() => {});
    }

  }
};
</script>
